package com.video.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.video.common.dto.ApproveDto;
import com.video.common.dto.UserDto;
import com.video.common.lang.Result;
import com.video.entity.User;
import com.video.service.UserService;
import com.video.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/approve")
public class ApproveController {

    @Resource
    private UserService userService;

    @RequiresAuthentication
    @GetMapping("/list")
    public Result listApproveUser(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "10") Integer pageSize){
        Long userId = ShiroUtils.getProfile().getId();

        Page<UserDto> page = new Page<>(currentPage, pageSize);

        IPage<UserDto> approveUserList = userService.getApproveUserList(page, userId);

        return Result.success(approveUserList);
    }

    @RequiresAuthentication
    @PostMapping("/save")
    public Result save(@Validated @RequestBody ApproveDto approveDto){
        User user = new User();
        user.setId(approveDto.getUserId());
        user.setApproveState(approveDto.getApproveState());
        userService.updateById(user);

        return Result.success(null);
    }

}
